home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / dynamenu / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  3.4 KB  |  134 lines

  1. // mainfrm.cpp
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1999 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. //
  13. // Purpose: implementation of the CMainFrame class
  14. //
  15. // Functions:
  16. //      Most of this file was generated by AppWizard.  The functions
  17. //      which contain code specific to this sample are:
  18. //
  19. //      CMainFrame::GetMessageString()   -- override of CFrameWnd::GetMessageString
  20. //                                          to customize message on status bar
  21.  
  22. #include "stdafx.h"
  23. #include "dynamenu.h"
  24.  
  25. #include "mainfrm.h"
  26. #include "dmdoc.h"    // for color definitions
  27.  
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char BASED_CODE THIS_FILE[] = __FILE__;
  31. #endif
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CMainFrame
  35.  
  36. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  37.  
  38. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  39.     //{{AFX_MSG_MAP(CMainFrame)
  40.     ON_WM_CREATE()
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CMainFrame construction/destruction
  46.  
  47. CMainFrame::CMainFrame()
  48. {
  49. }
  50.  
  51. CMainFrame::~CMainFrame()
  52. {
  53. }
  54.  
  55. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  56. {
  57.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  58.         return -1;
  59.  
  60. #if (_WIN32_WCE > 200)
  61.     if(!m_wndCommandBar.Create(this) ||
  62.        !m_wndCommandBar.InsertMenuBar(IDR_MAINFRAME) ||
  63.        !m_wndCommandBar.AddAdornments())
  64.     {
  65.         TRACE0("Failed to create CommandBar\n");
  66.         return -1;      // fail to create
  67.     }
  68. #else // MFC for Windows CE 1.0 and 2.0
  69.     if(!AddAdornments(0))
  70.     {
  71.         TRACE0("Failed to create CommandBar\n");
  72.         return -1;      // fail to create
  73.     }
  74. #endif
  75.  
  76.     return 0;
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CMainFrame diagnostics
  81.  
  82. #ifdef _DEBUG
  83. void CMainFrame::AssertValid() const
  84. {
  85.     CFrameWnd::AssertValid();
  86. }
  87.  
  88. void CMainFrame::Dump(CDumpContext& dc) const
  89. {
  90.     CFrameWnd::Dump(dc);
  91. }
  92.  
  93. #endif //_DEBUG
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CMainFrame message handlers
  97.  
  98. void CMainFrame::RefreshColorMenu()
  99. {
  100.     // Get the active document
  101.     CDynaMenuDoc* pDoc = (CDynaMenuDoc*)GetActiveDocument();
  102.     ASSERT_KINDOF(CDynaMenuDoc, pDoc);
  103.  
  104.     CMenu* pTopMenu = AfxGetMainWnd()->GetMenu();
  105.     CMenu* pColorMenu = pTopMenu->GetSubMenu(1);
  106.     
  107.     // Delete existing color options
  108.     for (int i = 0; i < NUM_TEXTCOLOR; i++)
  109.         pColorMenu->DeleteMenu(pDoc->m_aColorDef[i].m_nID, MF_BYCOMMAND);
  110.  
  111.     // Delete the separator
  112.     if (pColorMenu->GetMenuItemID(0) == 0)    // SEPERATOR
  113.         pColorMenu->DeleteMenu(0, MF_BYPOSITION);
  114.  
  115.     int nColors = 0;
  116.     // Insert chosen color options
  117.     for (i = 0; i < NUM_TEXTCOLOR; i++)
  118.     {
  119.         if (pDoc->m_abAllowColor[i] == TRUE)
  120.         {
  121.             CString strColor;
  122.             strColor.LoadString(pDoc->m_aColorDef[i].m_nString);
  123.             pColorMenu->InsertMenu(ID_COLOR_OPTIONS, MF_STRING,
  124.                 pDoc->m_aColorDef[i].m_nID, strColor);
  125.             nColors++;
  126.         }
  127.     }
  128.  
  129.     // Add separator if there are any color options
  130.     if (nColors > 0)
  131.         pColorMenu->InsertMenu(ID_COLOR_OPTIONS, MF_SEPARATOR,
  132.             0, _T(""));
  133. }
  134.